import java.util.Stack;

/**
 * Created by wty on 16/9/30.
 */
public class StringTest2 {
    public static void main(String[] args) {
        String a = "as#*ad#*ac";
        String b = "asadfaadsdfbac";
        Integer i = 0, j = 0;
        Stack<Integer> backPos = new Stack<Integer>();
        boolean isScanStar = false;
        for (; i < a.length() && j<b.length(); i++, j++) {
            System.out.println(a.charAt(i)+" -"+b.charAt(j));
            if (a.charAt(i) == '#' || a.charAt(i) == b.charAt(j)) {
                System.out.println("correct");
                isScanStar = false;
                continue;
            }
            else if(a.charAt(i) != '*'){
                if (!backPos.empty()) {
                    i = backPos.pop();
                    isScanStar =  true;
                } else {
                    System.out.println("false");
                    return;
                }
            }
            if (a.charAt(i) == '*' || isScanStar) {
                System.out.println("* starts");
                System.out.println(isScanStar);
                if (!isScanStar) {
                    i++;
                    j++;
                }
                isScanStar = true;
                backPos.push(i);
                while (i < a.length() && j < b.length() && a.charAt(i) != '#' && a.charAt(i) != b.charAt(j)) {
                    System.out.println("letter:" + a.charAt(i) + " -" + b.charAt(j));
                    j++;
                }
                //System.out.println("letter:" + a.charAt(i) + " -" + b.charAt(j));
                System.out.println("* ends");
                isScanStar = false;
            }
        }

        if (i == a.length()) System.out.println("success");
        else System.out.println("false");
    }
}
